﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace mitasoft.Books.Client.Desktop.Helpers
{
    internal class XMLHelper
    {
        public XMLHelper()
        {

        }

        /// <summary>
        /// Deserialize an XML
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static T Deserialize<T>(Stream stream)
        {
            System.Xml.Serialization.XmlSerializer deserialize = new System.Xml.Serialization.XmlSerializer(typeof(T));
            return (T)deserialize.Deserialize(stream);
        }

        /// <summary>
        /// Serialize to XML
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="instance"></param>
        /// <param name="fileToWrite">path stream</param>
        public static void Serialize<T>(object instance, Stream fileToWrite)
        {
            System.Xml.Serialization.XmlSerializer serialize = new System.Xml.Serialization.XmlSerializer(typeof(T));
            serialize.Serialize(fileToWrite, instance);
        }
    }
}
